<template>
  <div class="process-m2">
    <div class="chooseGroup-wwrap">
      <choose-group ref='chooseGroup' @select="selectFunc" />
    </div>
    <div @click="onClickRight" class="operator-bar">
      <van-button :loading="loading" type="primary">完成</van-button>
    </div>
  </div>
</template>
<script>
/* eslint-disable */
import ChooseGroup from '@/components/mobile-choose-group'
import process from '@/api/process'
import { Dialog, Toast } from 'vant';
import { getParameterByName } from '@/utils/util'
export default {
  components: {
     ChooseGroup,
  },
  data () {
    return {
      message: '',
      loading: false,
      taskId: getParameterByName('taskId'),
    }
  },
  mounted () {
  },
  methods: {
    selectFunc(item){
      console.log(item.uid)
    },
    onClickLeft(){
      this.$router.push({ path: '/process-tpl' + window.location.search })  
    },
    onClickRight(){
      Dialog.confirm({
        title: '确认提交吗？',
      })
      .then(() => {
        this.transferTask();
      })
      .catch(() => {
        // on cancel
      });
    },
    transferTask(){
      if ( !this.$refs.chooseGroup.uid ){
        Toast('请选择人员');
        return
      }
      this.loading = true;
      const params = {
        // 处理意见
        comment: '',
        // 当前任务ID
        taskId: this.taskId,
        assigneeId: "",
        variables: {}
      };
      params.assigneeId = this.$refs.chooseGroup.uid;
      process.transferTask(params).then(res => {
        if ( res.code === 0 ) {
          this.$message.success('转办操作提交成功');
          window.history.go(-2);
        }else {
          this.$message.error(res.msg);
        }
        this.loading = true;
      }).catch( r =>{
        this.loading = false;
      }); 
    },
  }
}
</script>

<style lang="less">
body{
  min-width: auto;
}
.process-m2{
  height: 100%;
  position: relative;
  .chooseGroup-wwrap{
    height: calc(100% - 60px);
  }
  .operator-bar{
    display: flex;
    justify-content: center;
    align-items: center;
    position: absolute;
    bottom: 0;
    height: 60px;
    width: 100%;
    border-top: 1px solid #f2f2f2;
    background: #fff;
    color: #409EFD;
    cursor: pointer;
    .van-button{
      color: #409EFD;
      width: 100%;
      background-color: #fff;
      border-color: #fff;
    }
  }
}
</style>
